package com.dev.utils.app;


import com.dev.utils.LogPrintUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.Rect;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;
import ohos.media.image.common.PixelFormat;


/**
 * detail: 截图工具类
 *
 * @author Ttt
 * <pre>
 *     截图
 *     @see <a href="https://www.cnblogs.com/angel88/p/7933437.html"/>
 *     WebView 截长图解决方案
 *     @see <a href="https://www.jianshu.com/p/0faa70e88441"/>
 *     X5 WebView 使用 snapshotWholePage 方法清晰截图
 *     @see <a href="https://www.v2ex.com/t/583020"/>
 * </pre>
 */
public class CapturePictureUtils {
    private CapturePictureUtils() {
    }

    // 日志 TAG
    private static final String TAG = CapturePictureUtils.class.getSimpleName();

    // Bitmap Config
    private static PixelFormat BITMAP_CONFIG = PixelFormat.RGB_565;
    // Canvas 背景色
    private static int BACKGROUND_COLOR = Color.TRANSPARENT.getValue();
    // 画笔
    private static Paint PAINT = new Paint();

    // ===========
    // = 配置相关 =
    // ===========

    /**
     * 设置 Bitmap Config
     *
     * @param config {@link PixelFormat}
     */
    public static void setBitmapConfig(final PixelFormat config) {
        if (config == null) return;
        BITMAP_CONFIG = config;
    }

    /**
     * 设置 Canvas 背景色
     *
     * @param backgroundColor 背景色
     */
    public static void setBackgroundColor(final int backgroundColor) {
        BACKGROUND_COLOR = backgroundColor;
    }

    /**
     * 设置画笔
     *
     * @param paint {@link Paint}
     */
    public static void setPaint(final Paint paint) {
        if (paint == null) return;
        PAINT = paint;
    }

    // ========
    // = 截图 =
    // ========

    // ============
    // = Activity =
    // ============

    /**
     * 获取当前屏幕截图, 包含状态栏 ( 顶部灰色 TitleBar 高度, 没有设置 theme 的 NoTitleBar 时会显示 )
     *
     * @param activity {@link AbilitySlice}
     * @return 当前屏幕截图, 包含状态栏
     */
    public static PixelMap snapshotWithStatusBar(final AbilitySlice activity) {
        try {

            // 获取屏幕宽度
           // int[] widthHeight = ScreenUtils.getScreenWidthHeight();

            ImageSource.SourceOptions sourceOptions= new ImageSource.SourceOptions();
            sourceOptions.formatHint = "image/jpg";
            //ImageSource imageSource = ImageSource.create()
            Rect frame = new Rect();
            frame = activity.getWindow().getBoundRect();
            // 创建新的图片
          //  PixelMap bitmap = PixelMap.create();
            // 释放绘图资源所使用的缓存
            //view.destroyDrawingCache();
            return null;
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "snapshotWithStatusBar");
        }
        return null;
    }
}
